import { Component } from '@angular/core';
import { IonicPage, NavController, LoadingController } from 'ionic-angular';
import { LoginProvider } from './login.provider';
import { RegPage } from '../reg/reg';
/**
 * Generated class for the LoginPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage({
  name:'login'
})
@Component({
  selector: 'page-login',
  templateUrl: 'login.html',
  providers: [LoginProvider]
})
export class LoginPage {


  user:any = {
    username:'zyc3',
    password:'123456',
    remember:false
  };
  constructor(public navCtrl: NavController, public loadingCtrl: LoadingController,private loginProvider: LoginProvider) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad LoginPage');
  }

  reg(){
    this.navCtrl.push(RegPage);
  }
  Event:any;
  submit(){
    console.log(this.user);

    let loading = this.loadingCtrl.create({
      content: 'Please wait...'
    });
  
    loading.present();
  
    this.Event = this.loginProvider.login(this.user).subscribe((res:any)=>{
      console.log(res);   
      loading.dismiss();
      localStorage.setItem('user',JSON.stringify(res.data));
      this.navCtrl.popToRoot();

      
    },(err:any)=>{
      
      setTimeout(()=>{
        loading.dismiss();
      },100);
    });
  

    // this.service.login(this.user);
  }

  very(){
    this.loginProvider.very().subscribe((res:any)=>{
      console.log(res);
      
    },(err:any)=>{
    },()=>{
    });
  }
}
